<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>登录</title>
    <script src="https://cdn.bootcss.com/zepto/1.2.0/zepto.min.js"></script>
    <script src="https://cdn.bootcss.com/blueimp-md5/2.7.0/js/md5.min.js"></script>
  <!--<link href='https://fonts.googleapis.com/css?family=Roboto:400,100,100italic,300,300italic,400italic,500,500italic,700,700italic,900italic,900&subset=latin,greek,greek-ext,vietnamese,cyrillic-ext,latin-ext,cyrillic' rel='stylesheet' type='text/css'>-->

  <!-- build:css({.tmp/serve,src}) styles/vendor.css -->
  <!-- bower:css -->
  <!-- run `gulp inject` to automatically populate bower styles dependencies -->
  <!-- endbower -->
  <!-- endbuild -->

  <!-- build:css({.tmp/serve,src}) styles/auth.css -->
  <!-- inject:css -->
  <!-- css files will be automatically insert here -->
  <!-- endinject -->
  <!-- endbuild -->
</head>
<body>
<main class="auth-main">
  <div class="auth-block">
    <h1>登录</h1>
    <!--<a href="reg.html" class="auth-link">还不是用户，去注册！</a>-->
    <form class="form-horizontal" id="loginForm">
      <div class="form-group">
        <label for="inputEmail3" class="col-sm-2 control-label">手机号</label>
        <div class="col-sm-10">
            <!--<div class="form-control signintell">
                <select  class="signintellfront">
                    <option  style="background-color:#CCFFFF" value="86-">+86</option>
                    <option  style="background-color:#CCFFFF" value="852-">+852</option>
                    <option  style="background-color:#CCFFFF" value="853-">+853</option>
                    <option  style="background-color:#CCFFFF" value="866-">+866</option>
                </select>
                <input type="tel" placeholder="手机号" class="signintellback">
            </div>-->
            <input type="tel" placeholder="手机号" class="form-control">
        </div>
      </div>
      <div class="form-group">
        <label for="inputPassword3" class="col-sm-2 control-label">密码</label>
        <div class="col-sm-10">
            <input type="password"  class="form-control"  placeholder="密码">
        </div>
      </div>
      <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
          <button type="submit" class="btn btn-default btn-auth" >登录</button>
          <!--<a href class="forgot-pass">忘记密码?</a>-->
        </div>
      </div>
    </form>


  </div>
</main>
</body>
<script>
    (function () {
        var host = '';
        //设置cookie
        function setCookie(c_name,value,expiredays)
        {
            var exdate=new Date()
            exdate.setDate(exdate.getDate()+expiredays)
            document.cookie=c_name+ "=" +escape(value)+
                ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
        }
        //提交表单
        $('#loginForm').submit(function () {
            var tel = $('input[type="tel"]').val(),
                pwd = $('input[type="password"]').val();

            if(!tel){
                alert('请输入用户名！');
                return false;
            }else if(!pwd){
                alert('请输入密码！');
                return false;
            }
            $.ajax({
                type:'POST',
                url: host+'/api/users/getSalt',
                data:{
                    uName : '86-'+tel
                },
                success:function (json) {
                    if(json.nFlag==1){
                        $.ajax({
                            type:'POST',
                            url:host+'/api/users/Login',
                            data:{
                                isBackground: true,
                                strPassword : md5(json.data.strSalt+pwd),
                                nUserId : json.data.nUserId,
                                t : new Date().getTime(),
                                strTokenId : json.data.strTokenId,
                                strHash : md5(json.data.strTokenId+json.data.nUserId)

                            },
                            success : function (data) {
                                // console.log(JSON.stringify(json));
                                if(data.nFlag==1){
                                    setCookie('strTokenId',data.data.strTokenId);
                                    setCookie('nUserId',data.data.nUserId);
                                    location.href = '/list';
                                }else{
                                    alert(data.strMessage);
                                }
                            }
                        })
                    }else {
                        alert(json.strMessage);
                    }
                }
            });
            return false;
        })
    })()
</script>
</html>